#pragma GCC optimize(2, "Ofast", "inline")
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <algorithm>
#define endl '\n'
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define int128 __int128_t
using namespace std;

// 已知
int n, x, m;
map<int, int> mp;

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i)cin >> x, mp[x]++;
    vector<int> ans;
    for (auto i : mp) ans.push_back(i.first);
    n = ans.size();
    int l = ans[n - 1] - ans[0];
    if (m >= n) l = 0;
    else if (m != 1) 
    {
        
    }
    cout << l << endl;
    return 0;
}

